from django.db import models

# Create your models here.

class Topic(models.Model):
    """
    用户学习主题
    """
    text = models.CharField(max_length=200) #CharField 由字符或者文本组成的数据
    date_added = models.DateTimeField(auto_now_add=True) #DateTimeField 记录日期和时间的数据
    def __str__(self):
        """返回模型的字符串表示"""
        return self.text

class Entry(models.Model):
    """学习到某个主题的具体知识"""
    topic = models.ForeignKey(Topic,on_delete=models.CASCADE) #这里必须传入2个参数
    text = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)
    class Meta:
        verbose_name_plural = "entries"
    def __str__(self):
        return self.text[:50]+"..."